_Pragma("once")

#include "pch.hpp"
#include "libmath.hpp"
#include "tool.hpp"
#include "texture.hpp"

namespace sdl_engine {

class Font final {
public:
    Font(const std::string& filename, int pt);
    Font(const Font&) = delete;
    ~Font();

    Font& operator=(const Font&) = delete;

    inline TTF_Font* Raw() { return font_; }

    Size GetUTF8Size(const std::string& text) const;
    Size GetTextSize(const std::string& text) const;
    inline int GetFontHeight() const { return TTF_FontHeight(font_); }

private:
    TTF_Font* font_;
    int pt_ = 0;
};

class TextTexture final {
public:
    TextTexture(Font& font);

    inline const std::string& GetText() const { return str_; }
    void SetText(const std::string& text);
    inline Texture& GetTexture() const {
        if (texture_)
            return *texture_.get();
        return Texture::Null;
    }
    inline Size GetSize() const { return GetTexture().GetSize(); }
    inline bool Valid() const { return texture_.get(); }
    inline Font& GetAttachedFont() { return font_; }

    void TryGenTexture();

private:
    Font& font_;
    std::string str_;
    Unique<Texture> texture_ = nullptr;
};

};
